package com.xinqing.test.objectpool;

import com.xinqing.test.objectpool.bean.MyBean;
import org.apache.commons.pool2.BaseKeyedPooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;

/**
 * @Author:CHQ
 * @Date:2020/10/26 11:18
 * @Description
 */
public class MyPoolFactory extends BaseKeyedPooledObjectFactory<String, MyBean> {

    @Override
    public MyBean create(String key) throws Exception {
        System.out.println("MyBean对象被创建了");
        //通过传递Key，创建Value逻辑
        return  new MyBean("chq", "23");
    }

    @Override
    public PooledObject<MyBean> wrap(MyBean myBean) {
        return new DefaultPooledObject<MyBean>(myBean);
    }
}
